package com.siyue.neo4j_demo.service.impl;

import com.siyue.neo4j_demo.dao.DongManRepository;
import com.siyue.neo4j_demo.entity.DongMan;
import com.siyue.neo4j_demo.service.DongManService;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DongManServiceImpl  implements DongManService {
    @Resource
    DongManRepository dongManRepository;

    @Override
    public DongMan addDongMan(DongMan dongMan) {
        return dongManRepository.save(dongMan);
    }

    @Override
    public DongMan getInfoById(long id) {
        return dongManRepository.findById(id).get();
    }

    @Override
    public void delById(long id) {
        dongManRepository.deleteById(id);
    }

    @Override
    public void createRelation(String from, String relation, String to) {
        dongManRepository.createRelation(from,relation,to);
    }

    @Override
    public void createRelationByName(String fromName) {
        dongManRepository.createRelationByName(fromName);
    }

    @Override
    public Page<DongMan> getListByPage(int current, int pageSize, String Name) {
        Pageable pageable= PageRequest.of(current,pageSize);
        return dongManRepository.findAll(pageable);
    }

    @Override
    public List<String> getAllRealationTypes() {
        return dongManRepository.getAllRealationTypes();
    }

    @Override
    public Boolean existById(long id) {
        return dongManRepository.existsById(id);
    }

    @Override
    public DongMan updateById(DongMan dongMan) {
        return dongManRepository.updateById(dongMan);
    }

    @Override
    public List<DongMan> getRelationsByName(String name,String relation) {
        return dongManRepository.getRelationsByName(name,relation);
    }

}
